<template>
  <!--项目计划信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      :formType="value.type"
      :labelWidth="140"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdateByDay } from '@/utils';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    //日期格式化年月
    formatDatesNoDay: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      return year + '-' + month;
    },
    init() {
      if (this.value.type === 'show') {
        this.initForm.forEach(x => {
          x.initialValue = this.value.row[x.fieldName];
          if (x.fieldName == 'activityMonth') {
            x.initialValue = formatdateByDay(this.value.row.activityMonth);
          }
        });
      }
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'INPUT',
          label: '项目编号',
          fieldName: 'planCode',
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '项目状态',
          fieldName: 'planStatus',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('2531')
        },
        // {
        //   type: 'INPUT',
        //   label: '事业部',
        //   fieldName: 'orgName',
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '经销商代码',
        //   fieldName: 'ownerCode',
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '经销商简称',
        //   fieldName: 'dealerName',
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '经销商全称',
        //   fieldName: 'dealerName',
        //   initialValue: ''
        // },
        {
          type: 'INPUT',
          label: '项目大类',
          fieldName: 'projectMainClassName',
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '项目小类',
          fieldName: 'projectSmallClassName',
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '项目车型',
          fieldName: 'modelLists',
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'DATE',
          label: '项目月份',
          fieldName: 'activityMonth',
          initialValue: '',
          placeholder: '',
          dateType: 'month'
        },
        {
          type: 'DATE',
          label: '开始日期',
          fieldName: 'planStartDate',
          initialValue: '',
          valueFormat: 'yyyy-MM-dd',
          placeholder: ''
        },
        {
          type: 'DATE',
          label: '结束日期',
          fieldName: 'planEndDate',
          initialValue: '',
          valueFormat: 'yyyy-MM-dd',
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '合作方式',
          fieldName: 'cooperationMethod',
          initialValue: '',
          placeholder: '',
          itemList: this.createDictList('2532')
        },
        // {
        //   type: 'INPUT',
        //   label: '方案编号',
        //   fieldName: 'programCode',
        //   initialValue: ''
        // },
        {
          type: 'TEXT_AREA',
          label: '方案名称',
          fieldName: 'programName',
          initialValue: '',
          selfCols: 2,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '项目名称',
          fieldName: 'projectName',
          initialValue: '',
          selfCols: 2,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '项目地点/投放平台',
          fieldName: 'realProjectLocation',
          initialValue: '',
          selfCols: 2,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '项目描述',
          fieldName: 'projectDesc',
          initialValue: '',
          selfCols: 2,
          placeholder: ''
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
    }
  },
  created() {
    this.init();
  }
};
</script>
